<?php

/**
 * 楼层品牌管理
 * @author Ice iceinto@mallog.com.cn
 */
class FloorBrandModel extends BaseModel
{

    public function getFbAll($mId, $fId)
    {
        $map = array();
        $data = array();
        $map['m_floor_brand.mid'] = $mId;
        $map['m_floor_brand.fid'] = $fId;
        $data = $this->field('m_floor_brand.*,m_brand.name,m_floor_brand_type.name as tName')
            ->where($map)
            ->join('LEFT JOIN m_brand ON m_brand.id = m_floor_brand.bid')
            ->join('INNER JOIN m_floor_brand_type ON m_floor_brand.tid = m_floor_brand_type.id')
            ->select();
        return $data;
    }

    /**
     * 执行添加
     * @param Array $data 数据
     * @author Ice iceinto@mallog.com.cn
     */
    public function fbAdd($data)
    {
        //唯一性判断
        $map = array();
        $map['mid'] = $data['mid'];
        $map['fid'] = $data['fid'];
        $map['bid'] = $data['bid'];
        $fb = $this->where($map)->find();
        if ($fb) {
            $this->status['status'] = 0;
            $this->status['doc'] = '本楼层已经存在当前品牌！';
        } else {
            $this->status['status'] = 1;
        }
        if ($this->status['status']) {
            //添加编辑记录和时间记录
            $data['add_time'] = time();
            $data['last_update'] = time();
            $data['editor'] = $_SESSION[C('USER_AUTH_KEY')];
            if ($this->add($data)) {
                $this->status['status'] = 1;
                $this->status['doc'] = '添加成功！';
            } else {
                $this->status['doc'] = '添加失败！';
            }
        }
        return $this->status;
    }

    /**
     * 执行修改
     * @param Array $data 数据
     * @author Ice iceinto@mallog.com.cn
     */
    public function fbUpdate($data)
    {
        //唯一性判断
        $this->theOnly($data['name'], 'name', '名称', true, array('id' => $data['id']));
        if ($this->status['status']) {
            //添加修改时间记录
            $data['last_update'] = time();
            if ($this->save($data)) {
                $this->status['status'] = 1;
                $this->status['doc'] = '添加成功！';
            } else {
                $this->status['doc'] = '添加失败！';
            }
        }
        return $this->status;
    }

}

?>